package xna.android;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.Rect;

//AINDA NAO FOI TESTADO
public class Scroller {

	ArrayList<Integer> sources;
	Bitmap currentImage, nextImage;
	Rect frame;
	int loadThis = 0;
	float speed = 0.1f;
	long lastUpdate = 0;
	Context content;
	
	public Scroller (Rect frame, Context content, Bitmap currentImage, Bitmap nextImage)
	{
		this.frame = frame;
		frame.offsetTo(0, currentImage.getHeight()-frame.height());
		this.content = content;
		this.sources = new ArrayList<Integer>();
		this.currentImage = currentImage;
		this.nextImage = nextImage;
	}
	
	public void AddSource(int source)
	{
		sources.add(source);
	}
		
	public void setSpeed(int speed) {
		this.speed = speed;
	}
	
	public void Update(long gameTime){
		if (lastUpdate != 0)
		{frame.offset(0, -(int)(speed*(gameTime-lastUpdate)));}
		lastUpdate = gameTime;
	}
	
	public void Draw(Canvas spriteBatch, Point pos)
	{
		Rect temp = new Rect(frame);
		temp.offsetTo(pos.x,pos.y);
		if (currentImage != null)
		{
			spriteBatch.drawBitmap(currentImage,frame,temp,null);
		}
		//if (frame.bottom-currentImage.getHeight()+nextImage.getHeight())
		if (nextImage != null){
		Rect sourceNext = new Rect(frame);
		sourceNext.offset(0, currentImage.getHeight());
		spriteBatch.drawBitmap(nextImage,sourceNext,temp,null);
		}
	}	
}
